<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="打卡时间" prop="clockTime">
        <!-- <el-date-picker
          clearable
          style="width: 340px"
          v-model="queryParams.clockTime"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        /> -->
        <el-date-picker
          type="date"
          value-format="yyyy-MM-dd"
          v-model="queryParams.clockStartTime"
          placeholder="开始日期"
        ></el-date-picker
        ><span>-</span
        ><el-date-picker
          type="date"
          v-model="queryParams.clockEndTime"
          value-format="yyyy-MM-dd"
          placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="打卡结果" prop="clockStatus">
        <el-select
          v-model="queryParams.clockStatus"
          placeholder="请选择打卡类型"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in this.getDictDatas(
              DICT_TYPE.ACCOMMODATION_CLOCK_STATUS
            )"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->

    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="学院" align="center" prop="collegeName" />
      <el-table-column label="系部" align="center" prop="departmentName" />
      <el-table-column label="班级" align="center" prop="className" />
      <el-table-column label="姓名" align="center" prop="clockUserName" />
      <el-table-column label="基准打卡" align="center" prop="standardTime" />
      <el-table-column
        label="打卡时间"
        align="center"
        prop="clockTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.clockTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="打卡结果" align="center" prop="clockStatus">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.ACCOMMODATION_CLOCK_STATUS"
            :value="scope.row.clockStatus"
          />
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加修改组件 -->
    <form-edit
      :show.sync="open"
      :title="title"
      @success="getList"
      ref="editDialog"
    ></form-edit>
  </div>
</template>

<script>
import {
  createClockRecord,
  updateClockRecord,
  deleteClockRecord,
  getClockRecord,
  getClockRecordPage,
  exportClockRecordExcel
} from "@/api/studentSide/clockRecord";
import formEdit from './formEdit'
import { mapGetters } from 'vuex';
export default {
  name: "ClockRecord",
  components: {
    formEdit
  },
  data() {
    return {
      showAudit: false,
      tags: [
        { name: '标签一', type: '' },
        { name: '标签二', type: '' },
        { name: '标签三', type: '' },
        { name: '标签四', type: '' },
        { name: '标签五', type: '' }
      ],
      showFeatures: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 打卡记录列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        // clockTime: [],
        clockStatus: null,
        clockStartTime: null,
        clockEndTime: null
      },

    };
  },
  computed: {
    ...mapGetters(['userId'])
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      let params = { ...this.queryParams, clockUserId: this.userId }
      // 执行查询
      getClockRecordPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.clockStartTime = null;
      this.queryParams.clockEndTime = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除打卡记录编号为"' + id + '"的数据项?').then(function () {
        return deleteClockRecord(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal.confirm('是否确认导出所有打卡记录数据项?').then(() => {
        this.exportLoading = true;
        return exportClockRecordExcel(params);
      }).then(response => {
        this.$download.excel(response, '打卡记录.xls');
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>
